package com.swak.consistency.core.logger;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.swak.consistency.ConsistencyLauncher;
import com.swak.consistency.core.context.ConsistencyContext;
import com.swak.utils.StringUtils;

/**
 * log.
 * 
 * @author 618lf
 */
public class ConsistencyLogger {

	/**
	 * 全局异常
	 */
	private static Logger logger = LoggerFactory.getLogger(ConsistencyLauncher.class);

	/**
	 * 是否Debug
	 * 
	 * @return
	 */
	public static boolean isDebugEnabled() {
		return logger.isDebugEnabled();
	}

	/**
	 * 打印调试信息
	 * 
	 * @param context
	 * @param content
	 */
	public static void debug(ConsistencyContext context, String content) {
		if (logger.isDebugEnabled()) {
			logger.debug(StringUtils.format("%s%s：%s", StringUtils.leftPad(StringUtils.EMPTY, context.getDepth(), "-"),
					content, context.toString()));
		}
	}

	/**
	 * 打印错误信息
	 * 
	 * @param context
	 * @param content
	 * @param e
	 */
	public static void error(ConsistencyContext context, String content, Throwable e) {
		logger.error(StringUtils.format("%s%s%s", StringUtils.leftPad(StringUtils.EMPTY, context.getDepth(), "-"),
				content, context.toString()), e);
	}
}
